package fr.psm.action;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.Preparable;

import fr.psm.bean.User;
import fr.psm.bean.UserId;
import fr.psm.service.UserService;

/**
 * 
 * @author "SAHMI MOHAMMED"
 *
 */
public class ListUserAction implements Preparable {

	/** The log file **/
	private static final Log LOG = LogFactory.getLog(ListUserAction.class);
	
	/** The initial parametres **/
	private UserService service;
	private List<User> listUsers;
	private User user;
	private String id;
	private int countNumberOfUsers;
	
	/**
	 * 
	 * @param service
	 */
	public ListUserAction(UserService service) {
		this.service = service;
	}
	

	/**
	 * 
	 * @return
	 */
	public String execute() {
		this.countNumberOfUsers = service.countNumberOfUsers();
		LOG.info(countNumberOfUsers);
		this.listUsers = service.getAll();
		return Action.SUCCESS;
	}
	
	
	public String saveUser(){
		LOG.debug("log");
		service.save(user, user.getId().toString());
		return Action.SUCCESS;
	}
	
	public String deleteUser(){
		User u = this.user;
		LOG.info(id);
		service.deleteById(user, user.getId().toString());
		return Action.SUCCESS;
	}

	/**
	 * 
	 */
	public void prepare() throws Exception {
		LOG.info("Methode prepare, not yet implimented");

	}

	public List<User> getListUsers() {
		return listUsers;
	}

	public void setListUsers(List<User> listUsers) {
		this.listUsers = listUsers;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}


	public String getId() {
		return id;
	}


	public void setId(String id) {
		this.id = id;
	}

}
